package com.jeff.android.lab.module.anim;

import android.view.View;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jeff.android.lab.BaseFragment;
import com.jeff.android.lab.R;
import com.jeff.android.lab.module.anim.loading.LoadingAnimFragment;
import com.jeff.android.lab.module.anim.path.AnimTestFragment;
import com.jeff.android.lab.module.anim.property.PropertyAnimFragment;
import com.jeff.android.lab.util.RouterUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;

/**
 * @author: duff
 * @date: 2019/1/14
 * @since: 1.0.0
 */
public class AnimMainFragment extends BaseFragment {
    @BindView(R.id.ptr) PtrClassicFrameLayout mPtr;
    @BindView(R.id.rlv) RecyclerView mRecyclerView;

    private List<String> mAnimTypes = new ArrayList<String>() {
        {
            add("PropertyAnim"); // 属性动画
            add("FrameAnim"); // 帧动画
            add("ViewAnim"); // 视图/补间动画
            add("PathAnim");
            add("VectorAnim"); // 矢量图
            add("LoadingAnim"); // 通用加载动画
        }
    };

    @Override
    protected int getRootLayout() {
        return R.layout.common_ptr_recycler_view;
    }

    @Override
    protected void initData() {
        mPtr.setEnabled(false);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        mRecyclerView.setAdapter(mAnimAdapter);
        mAnimAdapter.setNewData(mAnimTypes);
    }

    private void launch(String widget) {
        if ("PropertyAnim".equals(widget)) {
            RouterUtil.launchFragmentActivity(getContext(), PropertyAnimFragment.class);
        } else if ("FrameAnim".equals(widget)) {
        } else if ("ViewAnim".equals(widget)) {
        } else if ("PathAnim".equals(widget)) {
            RouterUtil.launchFragmentActivity(getContext(), AnimTestFragment.class);
        } else if ("VectorAnim".equals(widget)) {
        } else if ("LoadingAnim".equals(widget)) {
            RouterUtil.launchFragmentActivity(getContext(), LoadingAnimFragment.class);
        }
    }

    BaseQuickAdapter mAnimAdapter =
            new BaseQuickAdapter<String, BaseViewHolder>(R.layout.common_simple_item_text) {
                @Override
                protected void convert(BaseViewHolder helper, final String item) {
                    TextView text = helper.getView(R.id.tv_simple_item);
                    text.setText(item);

                    helper.itemView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            launch(item);
                        }
                    });
                }
            };

}
